<?php
set_time_limit(0);
include_once('../common.inc.php');
include_once(_INC_PATH.'database.php');

$ori_url = 'http://hi.baidu.com/stresume/blog/category/%CA%FD%BE%DD%BF%E2/index/';
$host = 'http://hi.baidu.com';
for($i=0; $i<=3; $i++)
{
	$html = file_get_contents($ori_url.$i);
	preg_match_all('#<div class=tit>(.*)</div>#isU',$html,$matches);
	unset($matches[1][0]);
	$urlArr = $matches[1];unset($matches);
	foreach($urlArr as $key=>$value)
	{
		$temprow = array();
		preg_match('#<a href="(.*)"(.*)>(.*)</a>#isU',$value,$matches);
		$url = $host.$matches[1];
		$temprow['title'] = iconv('gbk','utf-8',$matches[3]);
		$detalHtml = iconv('gbk','utf-8',file_get_contents($url));
		preg_match('#<div class=date>(.*)</div>#isU',$detalHtml,$matches);
		$date = $matches[1];
		$date = preg_replace('#\s(.*)\s#isU',' ',$date);
		$replaceArr = array('年','月');
		$date = str_replace($replaceArr,'-',$date);
		$date = str_replace('日','',$date);
		$temprow['mTime'] = strtotime($date);
		$temprow['addTime'] = strtotime($date);
		preg_match('#<div id=blog_text class=cnt>(.*)</div></table>#isU',$detalHtml,$matches);
		$content = $matches[1];
		$temprow['authorId'] = 'admin';
		$temprow['authorName'] = '百企编辑部';
		$temprow['published'] = '0';
		$temprow['cid'] = '4';
		if(!$db){
			$db = new database();
		}
		$techId = $db->insert($temprow,'tbl_tech');
		if($techId > 0){
			$contentrow = array();
			$contentrow['techId'] = $techId;
			$contentrow['content'] = mysql_escape_string($content);
			$db->insert($contentrow,'tbl_tech_content');
		}
	}
}


echo "finish--database";
